
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
 // ERROR: Not supported in C#: OptionDeclaration
namespace NCS_CS
{
	internal class Cjxtl
	{
		private _CCard card1;

		public double deltaPrevPrevPower;
		public double deltaPrevPower;
		public double deltaPower;
		public double PrevOutV;
		double pidp;
			//OUTC = 2
		int outc;
			//= method1.c.chanel
		int getC;
		public void setpidp(ref double v)
		{
			pidp = v;
		}

		public void setGetOut( int g, int o)
		{
			outc = o;
			getC = g;
		}
		public void setCard(ref _CCard v)
		{
			card1 = v;
		}

		//Public Sub StopPID()
		//End Sub


		//Public Function InitialPID(ByVal powerset As double) As Boolean
		//	'   PrevPower = 0
		//	'  Pav = 0
		//	'Dim power As Single
		//	'power = card1.getchanelVolt(getC) '/ 5# * 2048
		//	'Delta = powerset - power
		//	'    deltaPrevPrevPower = 0
		//	'    deltaPrevPower = 0
		//	'    PrevOutV = 0
		//	'    Call card1.newDA(outc, (0 + 10#) / 20# * 4095)
		//	'PrevPowerSet = powerset
		//	'outv = 0
		//End Function


		public void PID(double powerset)
		{
			double outv = 0;
			double tmp = 0;
			double power = 0;
			power = card1.getchanelVolt(getC);
			deltaPower = powerset - power;
			//tmp = 0.1225 * (deltaPower - deltaPrevPower) '2.45
			//tmp = tmp + 0.175 * deltaPower '3.5
			//tmp = tmp + 0.0625 * (deltaPower - 2 * deltaPrevPower + deltaPrevPrevPower) '1.25
			//tmp = tmp + 0.36 * deltaPower - 0.25 * deltaPrevPower + 0.0625 * deltaPrevPrevPower
			tmp = tmp + 0.3F * deltaPower - 0.2F * deltaPrevPower + 0.0625F * deltaPrevPrevPower;
			outv = PrevOutV + pidp * tmp;
			//2 * tmp '输出电压 为 检测电压变化量的二倍
			if (outv > 10) {
				outv = 10;
			}
			if (outv < -10) {
				outv = -10;
			}
			card1.newDA(outc, outv);
			deltaPrevPrevPower = deltaPrevPower;
			deltaPrevPower = deltaPower;
			PrevOutV = outv;
		}


		public Cjxtl() : base()
		{
			pidp = 1;
		}
	}
}
